/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ambartakip;

import java.awt.Color;
import java.awt.Component;
import java.awt.HeadlessException;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author monelge
 */
public class MusteriListesi extends javax.swing.JInternalFrame {

    /**
     * Creates new form MusteriListesi
     */
    String adi;

    public MusteriListesi(String _adi) {
        initComponents();
        this.adi = _adi;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable(){
            public Component prepareRenderer(TableCellRenderer renderer, int row, int column){
                Component returnComp = super.prepareRenderer(renderer, row, column);
                Color alternateColor = new Color(252,242,206);
                Color whiteColor = Color.WHITE;
                if (!returnComp.getBackground().equals(getSelectionBackground())){
                    Color bg = (row % 2 == 0 ? alternateColor : whiteColor);
                    returnComp .setBackground(bg);
                    bg = null;
                }
                return returnComp;
            }
        };

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jTable1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Kodu", "Adı", "Adres - 1", "Adres -2", "İlçe", "İl", "V.No", "V.Dairesi", "Tel - 1", "Tel - 2", "Şube"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setShowGrid(false);
        jTable1.setShowHorizontalLines(true);
        jTable1.setShowVerticalLines(true);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);
        if (jTable1.getColumnModel().getColumnCount() > 0) {
            jTable1.getColumnModel().getColumn(0).setMinWidth(50);
            jTable1.getColumnModel().getColumn(0).setHeaderValue("Kodu");
            jTable1.getColumnModel().getColumn(1).setMinWidth(300);
            jTable1.getColumnModel().getColumn(1).setHeaderValue("Adı");
            jTable1.getColumnModel().getColumn(2).setMinWidth(150);
            jTable1.getColumnModel().getColumn(2).setHeaderValue("Adres - 1");
            jTable1.getColumnModel().getColumn(3).setMinWidth(150);
            jTable1.getColumnModel().getColumn(3).setHeaderValue("Adres -2");
            jTable1.getColumnModel().getColumn(4).setMinWidth(50);
            jTable1.getColumnModel().getColumn(4).setHeaderValue("İlçe");
            jTable1.getColumnModel().getColumn(5).setMinWidth(50);
            jTable1.getColumnModel().getColumn(5).setHeaderValue("İl");
            jTable1.getColumnModel().getColumn(6).setMinWidth(50);
            jTable1.getColumnModel().getColumn(6).setHeaderValue("V.No");
            jTable1.getColumnModel().getColumn(7).setMinWidth(50);
            jTable1.getColumnModel().getColumn(7).setHeaderValue("V.Dairesi");
            jTable1.getColumnModel().getColumn(8).setMinWidth(75);
            jTable1.getColumnModel().getColumn(8).setHeaderValue("Tel - 1");
            jTable1.getColumnModel().getColumn(9).setMinWidth(75);
            jTable1.getColumnModel().getColumn(9).setHeaderValue("Tel - 2");
            jTable1.getColumnModel().getColumn(10).setMinWidth(50);
            jTable1.getColumnModel().getColumn(10).setHeaderValue("Şube");
        }

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1057, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        this.setTitle("Aranan Müşteri " + adi);
        try {
            ResultSet rs2 = _DataBase.datatable("select kodu,adi,adres1,adres2,ilce,il,vdairesi,vno, tel1,tel2,sube from krmuste where adi like '" + adi + "%'");

            int i = -1;
            while (rs2.next()) {
                i++;
                DefaultTableModel defaultModel = (DefaultTableModel) jTable1.getModel();
                //  ((DefaultTableModel) jTable1.getModel()).setRowCount(5);
                defaultModel.insertRow(i, new Object[]{rs2.getString(1), rs2.getString(2), rs2.getString(3),
                    rs2.getString(4), rs2.getString(5), rs2.getString(6), rs2.getString(7), rs2.getString(8), rs2.getString(9),
                    rs2.getString(10), rs2.getString(11)});
            }

        } catch (SQLException | HeadlessException e) {
            System.out.println(e.getMessage());
        }

        this.setFocusable(true);
    }//GEN-LAST:event_formInternalFrameOpened

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        if (evt.getClickCount() == 2) {

            KargoTakip.alici_kodu.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 0));
            KargoTakip.alici_adi.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 1));
            KargoTakip.alici_adres1.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 2));
            KargoTakip.alici_adres2.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 3));
            KargoTakip.alici_ilce.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 4));
            KargoTakip.alici_il.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 5));
            KargoTakip.alici_vd.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 6));
            KargoTakip.alici_no.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 7));
            KargoTakip.alici_tel.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 8));
            KargoTakip.alici_fax.setText((String) jTable1.getValueAt(jTable1.getSelectedRow(), 9));

            this.setVisible(false);

        }

        // TODO add your handling code here:
    }//GEN-LAST:event_jTable1MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
